from wx.core import Panel
from .common import *

SUCCESS = 1
FAILURE = 0

try:
    import pandas as pd
    import numpy as np
    IMPORT_STATUS = SUCCESS
except:
    IMPORT_STATUS = FAILURE

class BasePandasPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.switch_import = 0
        self._init_UI()

        if 1 == self.switch_import:
            return

    def _init_UI(self):

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        self.SetBackgroundColour(wx.WHITE) # CON_COLOR_MAIN

        self.panel = wx.Panel(self, wx.ID_ANY)
        self.panelSizer = wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(self.panelSizer)
        self.panelSizer.SetSizeHints(self.panel)
        sizer.Add(self.panel, 1, wx.EXPAND)

        self.scollPanel = scrolledpanel.ScrolledPanel(self.panel, -1) # 定义滚动面板
        self.scollPanel.SetupScrolling() # 开启滚动
        self.scollPanelSizer = wx.BoxSizer(wx.VERTICAL)
        self.scollPanel.SetSizer(self.scollPanelSizer)
        self.panelSizer.Add(self.scollPanel, 1, wx.EXPAND | wx.ALL, 2) # 加入主容器

        if FAILURE == IMPORT_STATUS: # 提醒必须要引入库
            info = wx.StaticText(self.scollPanel, -1, '请先安装pandas、numpy、matplotlib，然后重启本工具，才能使用本页功能。【主环境安装】')
            info.SetForegroundColour(wx.RED)
            info.SetFont(wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
            self.scollPanelSizer.Add(info, 1, wx.EXPAND | wx.ALL, 8)
            self.switch_import = 1
            return

        '''
            pandas 的操作合集
        '''
        self._init_UI_pandas()

    def _init_UI_pandas(self):
        '''pandas 的操作合集'''
        """
            输入输出
        """
        self.cp_inoutput = wx.CollapsiblePane(self.scollPanel, label = 'Input/Output', style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
        self.scollPanelSizer.Add(self.cp_inoutput, 0, wx.RIGHT|wx.LEFT|wx.EXPAND, 25)
